
export ROOT = ${shell pwd}
TARGET = services
LIBS := pthread
INCLUDES :=	${ROOT}

RM := rm -f

PS = c

#CC = powerpc-linux-gnu-gcc
CC = gcc
CFLAGS = -g -Wall -O3
CFLAGS += $(addprefix -I,$(INCLUDES))
CFLAGS += -MMD

SOURCE :=	$(wildcard *.$(PS)) 		\
			$(wildcard uart/*.$(PS))	\
			$(wildcard log/*.$(PS))
			
OBJS := $(patsubst %.$(PS),%.o,$(SOURCE))
DEPS := $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.$(PS),$(MISSING_DEPS)))

.PHONY : all deps objs clean rebuild

all : $(TARGET)
	
deps : $(DEPS)
	$(CC) -MM -MMD $(SOURCE)

objs : $(OBJS)

clean :
	$(RM) ${OBJS}
	$(RM) ${DEPS}
	$(RM) $(TARGET)

rebuild: clean all 

ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
	$(RM) $(patsubst %.d,%.o,$@)
endif

-include $(DEPS)

$(TARGET) : $(OBJS)
	$(CC) -o $(TARGET) $(OBJS) $(addprefix -l,$(LIBS))
